<?php
/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/12
 * Time: 10:13
 */

namespace App\admin\TableView;


use App\admin\TableView\BaseClass\BaseViewList;
use App\Jobs\Fun;
use App\Models\Admin\ApilistModel;
use App\Models\Main\MsgSysModel;
use App\Models\MoneyBilModel;

class MsgSystemView extends BaseViewList
{

    public function get_model()
    {

        return new MsgSysModel();
    }

    public $show_add = true; ///显示添加按钮
    /**
     * 是否显示删除按钮
     */
    public $show_delete = true;
    public $topTitle = '系统消息';
    public $PageSize = 10;

    public $breadcrumb = '<li><a href="/mcadmin">Home</a></li>
        <li><a href="javascript:;">系统消息</a></li>
        ';

    public $html = '';


    //  public $show_add = false; ///显示添加按钮

    /**
     * 获取表格的唯一名字
     */
    public function getName()
    {
        return 'MsgSysModel';
    }


    /**
     * 需要继承,然后定义每行需要显示的数据格式
     */
    public function Labels()
    {
        return array(
            //   BaseViewList::Button_checkbox=>[],
            'id' => 40,
            'title'=>50,
            'detail'=>50,
            'created_at'=>50,
            BaseViewList::Button_control => [

                BaseViewList::Button_Edit,
                  BaseViewList::Button_Delete

            ]
        );
    }

    /**
     * 对话框中的各个字段
     */
    public function dialog()
    {
        return array(

            array(
                'zd' => 'title',
                'type' => self::dialog_text
            ),
            array(
                'zd' => 'detail',
                'type' => self::dialog_textarea
            ),
        );
    }

    /**
     * 方便继承,多一层过滤
     */
    public function ModelTohtml($key, $model)
    {

        if($key=='created_at'){
            return Fun::date($model->$key);
        }

        return parent::ModelTohtml($key, $model);
    }


    /**
     * 方便重载,保存model时调用的,可能是新增也可能是保存,返回true表示允许保存
     */
    public function save_model($model) {
        if(!$model->created_at){
            $model->created_at=time();
        }
        return true;
    }

}